<?php

class xuqiuControl extends publicControl{
	function add(){//添加需求页面
		C("debug",0);
		$this->head();
		$this->change();
		$this->display();	
	}

	function change(){//栏目分类选择
		$cid=isset($_GET['cateid'])?$_GET['cateid']:'';
		// if(empty($cid)){
			$db=M('category');
			$cate=$db->all();
			$this->assign("cate",$cate);
			if(!empty($cid)){
				$self=$db->field("cateid,cname,level,pid")->where("cateid='$cid'")->find();
				$pid1=$self['pid'];
				if($self['level']==2){
				$parent=$db->field("cateid,cname,pid")->where("cateid='$pid1'")->find();
				$pid2=$parent['pid'];
				$pparent=$db->where("cateid='$pid2'")->find();
				$this->assign("parent",$parent);
				$this->assign("pparent",$pparent);
				$this->assign("self",$self);
			}
			

		}

	}


	function xuqiu_add(){//完成添加
		C("debug",1);
		$time=isset($_POST['time'])?$_POST['time']:'30';
		$time=$time*24*3600+time();
		$_POST['time']=date("y-m-d",$time);
		$info=$_POST['con'];
		$db=M("xuqiu");
		$num=$db->add();
		$data=M("data");
		$_POST['phone']=(int)$_POST['phone'];
		$_POST['xid']=$num;
		$_POST['uid']=isset($_SESSION['uid'])?$_SESSION['uid']:'';
		$thumb=M("thumb");
		$data=array();
		foreach ($_POST['thumb'] as $v) {
			if(!empty($v)){
			$data['xid']=$num;
			$data['thumb']=$v;
			$thumb->add($data);
		}
		}
		// if($data->add()){
		// 	$this->success("发布成功");
		// }else{
		// 	$this->error("发布失败");
		// }
	}

	function xuqiu_show(){

		C('debug',0);
		$this->head();
		$id=$_GET['xid'];
		$list=M("list");
		$lid=isset($_GET['list'])?$_GET['list']:1;//排序的方法
		$by=$list->all();
		$this->assign("by",$by);
			foreach ($by as $v) {//如果没有要传排序方式的话用默认的不然就查找数据库中的方法
				if($lid==$v['lid']){
					$by=$v['by'];
				}	
			}
		$db=K("xuqiu");
		$rows=$db->where("xuqiu.xid='$id'")->order($by)->all();
		$list=$db->all();
		if($rows[0]['style']=='先交稿'){
		$this->assign("rows",$rows);
		$this->display();
		}else{
			$this->assign("rows",$rows);
			$this->display("xuqiu_show2");
		}
	}






}

 ?>